﻿@page "/panel"

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inject NorthwindContext dbContext

<RadzenExample Name="Panel">
<div class="row">
    <div class="col-xl-6">
        <h3>Panel</h3>
        <RadzenPanel AllowCollapse="true" Style="width:600px;margin-bottom: 20px; height:500px;"
                        Expand=@(() => Change("Panel expanded")) Collapse=@(() => Change("Panel collapsed"))>
            <HeaderTemplate>
                <span style="float:left;">
                    <RadzenIcon Icon="account_box" /><b style="font-size:30px">ORDER</b>
                </span>
            </HeaderTemplate>
            <ChildContent>
                <RadzenDataList PageSize="1" WrapItems="true" AllowPaging="true" 
                                Data="@orders" TItem="Order">
                    <Template Context="order">
                        <RadzenCard Style="width:300px;height:300px">
                            <div class="row">
                                <div class="col-md-6">
                                    <div>Company:</div>
                                    <b>@order.Customer?.CompanyName</b>
                                    <div style="margin-top:20px">Employee:</div>
                                    <b>@(order.Employee?.FirstName + " " + order.Employee?.LastName)</b>
                                    <br />
                                    <RadzenImage Path="@order.Employee?.Photo" Style="width:100px;" />
                                </div>
                                <div class="col-md-6">
                                    <div>Freight:</div>
                                    <b>@String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", order.Freight)</b>
                                    <div style="margin-top:20px">Ship country:</div>
                                    <b>@(order.ShipCountry)</b>
                                    <div style="margin-top:20px">Ship city:</div>
                                    <b>@(order.ShipCity)</b>
                                    <div style="margin-top:20px">Ship name:</div>
                                    <b>@(order.ShipName)</b>
                                </div>
                            </div>

                        </RadzenCard>
                    </Template>
                </RadzenDataList>
            </ChildContent>
            <SummaryTemplate>
                <RadzenCard>
                    @orders.Count() Orders
                </RadzenCard>
            </SummaryTemplate>
        </RadzenPanel>
    </div>
    <div class="col-xl-6">
        <EventConsole @ref=@console />
    </div>
</div>
</RadzenExample>

@code {
    EventConsole console;

    IEnumerable<Order> orders;

    protected override void OnInitialized()
    {
        orders = dbContext.Orders.Include("Customer").Include("Employee").ToList();
    }

    void Change(string text)
    {
        console.Log($"{text}");
    }
}